function [ Energy_Joule, Energy_eV, Wavelength, Wavenumber, Frequency ] = ...
            APEconvert( inputvalue, inputtype )
%[ Energy_Joule, Energy_eV, Wavelength, Wavenumber, Frequency ] = ...
%            APEconvert( inputvalue, inputtype )
%
% APEconvert converts between Energy (in eV), Wavelength (in nm),
%    Wavenumber (in cm^-1) and Frequency (in Hz).
%
% INPUT     inputvalue      :   Value to convert (see above)
%           inputtype       :   Identity of inputvalue
%                               'en' = Energy (in eV)
%                               'ej' = Energy (in Joule)
%                               'wl' = Wavelength (in nm)
%                               'wn' = Wavenumber (in cm^-1)
%                               'fq' = Frequency (in Hz)
%
% OUTPUT    Energy_Joule    :   in Joule
%           Energy_eV       :   in eV
%           Wavelength      :   in nm
%           Wavenumber      :   in 1/cm
%           Frequency       :   in Hz

%  (c) F. Dworkowski, 2011
%      Version 1.0, 2011-07-29


%% ===== CONFIG =====
h        = 6.626068e-34;    % Planck Constant, J/Hz
c        = 2.99792458e+8;   % Speed of Light, m/s
Joule2eV = 6.24150974e+18;  % Convert Joule to eV

% E = h x f 
% c = f x lambda

%% ===== CODE =====
if nargin < 2
    help APEconvert
    return
end

format shortG

switch inputtype
    case 'wn'           % Wavenumber
        Wavenumber   = inputvalue
        Wavelength   = (1/(Wavenumber))/1e-7
        Frequency    = c/(Wavelength*1e-9)
        Energy_eV    = (h*Frequency)*Joule2eV
        Energy_Joule = h*Frequency
        
    case 'en'           % Energy
        Energy_eV    = inputvalue
        Energy_Joule = inputvalue/Joule2eV
        Wavelength   = ((c*h)/Energy_Joule)*1e+9
        Wavenumber   = 1/(Wavelength*1e-7)
        Frequency    = c/(Wavelength*1e-9)
    case 'ej'
        Energy_Joule = inputvalue
        Energy_eV    = inputvalue*Joule2eV
        Wavelength   = ((c*h)/Energy_Joule)*1e+9
        Wavenumber   = 1/(Wavelength*1e-7)
        Frequency    = c/(Wavelength*1e-9)
    case 'fq'           % Frequency
        Frequency    = inputvalue
        Energy_eV    = (h*Frequency)*Joule2eV
        Energy_Joule = h*Frequency
        Wavelength   = (c/Frequency)/1e-9
        Wavenumber   = 1/(Wavelength*1e-7)
    case 'wl'           % Wavelength
        Wavelength   = inputvalue
        Wavenumber   = 1/(Wavelength*1e-7)
        Frequency    = c/(Wavelength*1e-9)
        Energy_eV    = (h*Frequency)*Joule2eV
        Energy_Joule = h*Frequency
        
    otherwise
        errordlg('Inputtype is wrong!')
        return
end

end

